/**
 * Created by Amaris on 2016/10/9.
 */

var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 通讯表
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'contact',
    tableName: 'tb_contact',
    connection: "mysql",
    attributes: {
        rowId: {
            type: 'string',
            unique: true,
            primaryKey: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function() {
                return uuid.v4();
            }
        },
        seller: {
            type: 'string',
            required: true,
            columnName: 'seller',
            model: 'seller'
        },
        name: {
            type: 'string',
            required: true,
            columnName: 'name'

        },
        phone: {
            type: 'string',
            required: true,
            columnName: 'phone'

        },
        tel: {
            type: 'string',
            columnName: 'tel'

        },
        extension: {
            type: 'string',
            columnName: 'extension'

        },
        email: {
            type: 'string',
            columnName: 'email'

        },
        des: {
            type: 'string',
            columnName: 'des'

        },
        industry: {
            type: 'string',
            columnName: 'industry'

        },
        department: {
            type: 'string',
            columnName: 'department'

        },
        position: {
            type: 'string',
            columnName: 'position'
        },

        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid'

        },

        toJSON: function() {
            var obj = this.toObject();
            obj.createdAt=moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt=moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');

            return obj;
        }
    }
});